{{- $linkMap := index .Site.Data "map" -}}
{{- $fileKey := substr .Path 1 -}}
{{- $linkFrom := slice -}}
{{- $linkTo := slice -}}
{{- range $linkMap -}}
{{- if eq $fileKey ( lower (index . 1)  | replaceRE " " "-"  )  -}}
{{- $linkFrom = $linkFrom | append (index . 0) -}}
{{- else if eq $fileKey ( lower (index . 0)  | replaceRE " " "-"  ) -}}
{{- $linkTo = $linkTo | append (index . 1) -}}
{{- end -}}
{{- end -}}

<div>Referenced From</div>
{{- range $index, $value := $linkFrom -}}
{{ $url := $value }}
<div class="popover-container content">
    {{- $url := replace $url "(" "" -}}
    {{- $url := replace $url ")" "" -}}
    <a href="{{ lower $url  | replaceRE " " "-"  | relURL }}/" class="popover-link" >{{ $index }}. {{  $url  }}</a>
    <span class="popover"></span><!-- popover content goes here -->
</div>

{{- end -}}

<div>References</div>
{{- range $index, $value := $linkTo -}}
{{ $url := $value }}
{{ if ( hasSuffix $url ".png" )}}
    <div class="popover-container content">
        <a href="https://note.ftls.xyz/{{ $url  }}" class="popover-link-img" target="_blank">{{ $index }}. {{  $value  }}</a>
        <span class="popover">
            <figure class="relative mb-8 overflow-hidden">
                <img src="https://note.ftls.xyz/{{ $url }}" alt="{{ $url | relURL }}" loading="lazy" data-zoomable>
                <figcaption>{{ $value }}</figcaption>
            </figure>
        </span>
    </div>
{{ else }}
    <div class="popover-container content">
        {{- $url := replace $url "(" "" -}}
        {{- $url := replace $url ")" "" -}}
        {{- $url := replace $url " " "-" -}}
        <a href="{{ lower $url  | relURL }}/" class="popover-link" >{{ $index }}. {{ $value }}</a>
        <span class="popover"></span>
    </div>
{{ end }}
{{- end -}}